#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
using LL = long long;
const int N = 2e5 + 10;

int m, p;
struct Node
{
    int l, r;
    int v;
}node[N * 4];

void build(int u, int l, int r){
    node[u].l = l;
    node[u].r = r;
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(u << 1, l, mid);
    build((u << 1) + 1, mid + 1, r);
}

void pushup(int u){
    node[u].v = max(node[u << 1].v, node[u << 1 | 1].v);
}

void modify(int u, int x, int k){
    if(node[u].l == x && node[u].r == x) {
        node[u].v = k;
    }else{
        int mid = (node[u].l + node[u].r) >> 1;
        if(x <= mid) modify(u << 1, x, k);
        else modify(u << 1 | 1, x, k);
        pushup(u);
    }
}

int query(int u, int l, int r){
    if(node[u].l >= l && node[u].r <= r) return node[u].v;

    int mid = (node[u].l + node[u].r) >> 1;
    int v = 0;
    if(mid >= l) v = query(u << 1, l, r);
    if(mid < r) v = max(v, query(u << 1 | 1, l, r));
    return v;
}


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    scanf("%d%d", &m, &p);
    int n = 0;

    build(1, 1, m);
    char op[2];
    int x;
    int last = 0;
    while(m --){
        scanf("%s%d", op, &x);
        if(op[0] == 'A'){
            n++;
            modify(1, n, ((LL)x + last) % p);
        }else{
            last = query(1, n - x + 1, n);
            printf("%d\n", last);
        }
    }



    return 0;
}